/*
 * @Author: xiguan
 * @Email: xiguan.teng@qq.com
 * @Version: 1.0
 * @Date: 2022-07-18 14:02:42
 * @LastEditTime: 2022-07-31 12:40:58
 */


#ifndef _CONSTRUCTMY_H_
#define _CONSTRUCTMY_H_

#include "TypeTraitsMy.h"
#include <new>

namespace MySTL{

    template<class T1, class T2>
    inline void construct( T1 *ptr1, const T2 &value){
        new(ptr1) T1(value); // 在 ptr1 指向的内存空间分配 T1 的对象，并调用 T1(T2) 的构造函数
    }

    template<class T>
    inline void destroy( T *ptr ){
        ptr->~T();
    }

    template<class ForwardIterator>
    inline void _destroy( ForwardIterator first, ForwardIterator last, _true_type ){
        
    }

    template<class ForwardIterator>
    inline void _destroy( ForwardIterator first, ForwardIterator last, _false_type ){
        for( ; first != last; ++ first ){
            destroy( &*first );
        }
    }

    template<class ForwardIterator>
    inline void destroy( ForwardIterator first, ForwardIterator last ){
        typedef typename _type_traits<ForwardIterator>::is_POD_type is_POD_type;

        _destroy( first, last, is_POD_type() );
    }

}


#endif